package com.fg.ihr.repository;
import com.fg.ihr.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


@Repository
public interface UserRepository extends JpaRepository<User, Integer>,JpaSpecificationExecutor<User> {
    @Transactional
    @Modifying
    @Query("UPDATE User u SET u.name = :name,u.password = :password where u.name = :name")
    void updateUserByName(@Param("name")String name, @Param("password")String password);

    @Query(nativeQuery = true,value="SELECT count(*) FROM user u WHERE u.name= :name")
    int selectByName(@Param("name")String name);

    User findByUsername(String username);
}
